home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dkbsrc.zip / VIEWPNT.C < prev    next >
C/C++ Source or Header  |  1991-05-04  |  4KB  |  125 lines

  1. /*****************************************************************************
  2. *
  3. *                                     viewpnt.c
  4. *
  5. *   from DKBTrace (c) 1990  David Buck
  6. *
  7. *  This module implements methods for managing the viewpoint.
  8. *
  9. * This software is freely distributable. The source and/or object code may be
  10. * copied or uploaded to communications services so long as this notice remains
  11. * at the top of each file.  If any changes are made to the program, you must
  12. * clearly indicate in the documentation and in the programs startup message
  13. * who it was who made the changes. The documentation should also describe what
  14. * those changes were. This software may not be included in whole or in
  15. * part into any commercial package without the express written consent of the
  16. * author.  It may, however, be included in other public domain or freely
  17. * distributed software so long as the proper credit for the software is given.
  18. *
  19. * This software is provided as is without any guarantees or warranty. Although
  20. * the author has attempted to find and correct any bugs in the software, he
  21. * is not responsible for any damage caused by the use of the software.  The
  22. * author is under no obligation to provide service, corrections, or upgrades
  23. * to this package.
  24. *
  25. * Despite all the legal stuff above, if you do find bugs, I would like to hear
  26. * about them.  Also, if you have any comments or questions, you may contact me
  27. * at the following address:
  28. *
  29. *     David Buck
  30. *     22C Sonnet Cres.
  31. *     Nepean Ontario
  32. *     Canada, K2H 8W7
  33. *
  34. *  I can also be reached on the following bulleton boards:
  35. *
  36. *     OMX              (613) 731-3419
  37. *     Mystic           (613) 596-4249  or  (613) 596-4772
  38. *
  39. *  Fidonet:   1:163/109.9
  40. *  Internet:  dbuck@ccs.carleton.ca
  41. *  The "You Can Call Me RAY" BBS    (708) 358-5611
  42. *
  43. *  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  44. *
  45. *     The "You Can Call Me RAY" BBS (708) 358-5611
  46. *     The Information Exchange BBS  (708) 945-5575
  47. *
  48. *****************************************************************************/
  49.  
  50. #include "frame.h"
  51. #include "vector.h"
  52. #include "dkbproto.h"
  53.  
  54. METHODS Viewpoint_Methods =
  55.    { NULL, NULL, NULL, NULL, Copy_Viewpoint,
  56.      Translate_Viewpoint, Rotate_Viewpoint,
  57.      Scale_Viewpoint, NULL};
  58.  
  59. void *Copy_Viewpoint (Object)
  60.    OBJECT *Object;
  61.    {
  62.    VIEWPOINT *Viewpoint = (VIEWPOINT *) Object;
  63.    VIEWPOINT *New_Viewpoint;
  64.  
  65.    New_Viewpoint = Get_Viewpoint();
  66.  
  67.    New_Viewpoint -> Location = Viewpoint -> Location;
  68.    New_Viewpoint -> Direction = Viewpoint -> Direction;
  69.    New_Viewpoint -> Right = Viewpoint -> Right;
  70.    New_Viewpoint -> Up = Viewpoint -> Up;
  71.    return (New_Viewpoint);
  72.    }
  73.  
  74. void Translate_Viewpoint (Object, Vector)
  75.    OBJECT *Object;
  76.    VECTOR *Vector;
  77.    {
  78.    VAdd (((VIEWPOINT *) Object) -> Location, 
  79.          ((VIEWPOINT *) Object) -> Location,
  80.          *Vector);
  81.    }
  82.  
  83. void Rotate_Viewpoint (Object, Vector)
  84.    OBJECT *Object;
  85.    VECTOR *Vector;
  86.    {
  87.    TRANSFORMATION Transformation;
  88.    VIEWPOINT *Viewpoint = (VIEWPOINT *) Object;
  89.  
  90.    Get_Rotation_Transformation(&Transformation, Vector);
  91.    MTransformVector (&(Viewpoint -> Location),
  92.                      &(Viewpoint -> Location), &Transformation);
  93.  
  94.    MTransformVector (&(Viewpoint -> Direction),
  95.                      &(Viewpoint -> Direction), &Transformation);
  96.  
  97.    MTransformVector (&(Viewpoint -> Up),
  98.                      &(Viewpoint -> Up), &Transformation);
  99.  
  100.    MTransformVector (&(Viewpoint -> Right),
  101.                      &(Viewpoint -> Right), &Transformation);
  102.    }
  103.  
  104. void Scale_Viewpoint (Object, Vector)
  105.    OBJECT *Object;
  106.    VECTOR *Vector;
  107.    {
  108.    TRANSFORMATION Transformation;
  109.    VIEWPOINT *Viewpoint = (VIEWPOINT *) Object;
  110.  
  111.    Get_Scaling_Transformation(&Transformation, Vector);
  112.    MTransformVector (&(Viewpoint -> Location),
  113.                      &(Viewpoint -> Location), &Transformation);
  114.  
  115.    MTransformVector (&(Viewpoint -> Direction),
  116.                      &(Viewpoint -> Direction), &Transformation);
  117.  
  118.    MTransformVector (&(Viewpoint -> Up),
  119.                      &(Viewpoint -> Up), &Transformation);
  120.  
  121.    MTransformVector (&(Viewpoint -> Right),
  122.                      &(Viewpoint -> Right), &Transformation);
  123.    }
  124.  
  125.